class InfosController < ApplicationController
	before_action :set_category,only:[:create,:new,:index,:update]
	def new
		@info=Info.new()
	end
	def create
		@categories.each do |category| 
			@info_categories=InfoCategory.where(parent_id: category.id)
			@info_categories.each do |ic|
				info=Info.create(value: params[:infos]["#{ic.id}"][:value],info_category_id: ic.id)
			end
		end
		redirect_to infos_path
	end
	def index
		@info_cate =Info.new
	end
	def update
		category=InfoCategory.where(parent_id: params[:id])
		category.each do |cate|
			info=Info.find_by_info_category_id(cate.id)
			# info.update(value: )
		end
		redirect_to infos_path
	end
	private
	def set_category
		@categories=InfoCategory.where(parent_id: nil)
	end
	def info_params
		params.require(:infos).permit(:info_category_id,:value)
	end
end
